//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CSlotLayout.cpp>
///	@path	~/src/graphics/dx9/
///	@date	2008/12/28
///	@desc	.

#include "config/config.h"

#include "graphics/common/CSlotLayout.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CSlotLayout );
	
	// CSlotLayout
	CSlotLayout::CSlotLayout( size_t size , const std::vector<VertSlotDecl>& layout )
		: m_size( size )
		, m_layout( layout )
	{
	}
	// ~CSlotLayout
	CSlotLayout::~CSlotLayout( void )
	{
	}
	// GetLayoutSize
	size_t CSlotLayout::GetLayoutSize( void )
	{
		return m_size;
	}
	// ExpandData
	bool CSlotLayout::ExpandData( uint index , const byte * input , size_t input_size , byte * output )
	{
		const VertSlotDecl& decl = m_layout[index];

		XS_ASSERT( index < m_layout.size() );
		XS_ASSERT( decl.size == input_size );
		memcpy( output , input , input_size );
		return true;
	}
	// StreamData
	bool CSlotLayout::StreamData( const byte * input , size_t stride , size_t count , byte * output )
	{
		XS_ASSERT( stride != m_size );
		size_t total = m_layout.size();
		const byte * pInput = input;
		byte * pOutput = output;
		for( size_t i = 0 ; i < count ; ++i , pInput += stride , pOutput += m_size )
		{
			const byte * src = pInput;
			byte * dst = pOutput;
			for( size_t j = 0 ; j < total ; ++j )
			{
				const VertSlotDecl& decl = m_layout[j];
				memcpy( dst , src , decl.size );
				src += decl.size;
				dst += decl.size;
			}
		}
		return true;
	}

} // namespace xeres
